﻿using BPMN.Domain.Interface;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BPMN.Infrastructure.Repository
{
    public class RepositoryBasetow<T> : IRepositoryBasetow<T> where T : class
    {
        public RepositoryBasetow(MyDbContext db)
        {
            Db = db;
        }

        public MyDbContext Db { get; }

        public bool Add(T entity)
        {
           Db.Set<T>().Add(entity);
            return SaveChanges();
        }

        public bool Delete(int id)
        {
          var model=Db.Set<T>().Find(id);
            Db.Set<T>().Remove(model);
            return SaveChanges();
        }

        public IQueryable<T> GetAll()
        {
           return Db.Set<T>().AsQueryable();
        }



        public bool SaveChanges()
        {
           return Db.SaveChanges()>0;
        }

        public bool Update(T entity)
        {
            Db.Set<T>().Update(entity);
  
            return SaveChanges();
        }
    }
}
